import { createStore } from 'vuex'

export default createStore({
  state: {
    checkHead:[], // 选中内存的数据
    checkColor:[], // 选中的颜色的数据
    allList:[], // 选中该显示的table数据
  },
  mutations: {
    addHead(state,val){
      let index = state.checkHead.findIndex(item => item == val);
      if (index>-1){
        state.checkHead.splice(index,1);
      } else {
        state.checkHead.push(val);
      }
      
      if (state.checkColor.length){
        state.checkColor.forEach(item => {
          state.allList = state.allList.filter(item => item.value && item.name);
          state.allList.push({name:val,value: item})
        })
      } else {
        state.allList.push({name:val,value:''})
      }

    },
    addColor(state,val){
      let index = state.checkColor.findIndex(item => item == val);
      if (index>-1){
        state.checkColor.splice(index,1);
      } else {
        state.checkColor.push(val);
      }

      if (state.checkHead.length){
        state.checkHead.forEach(item => {
          state.allList = state.allList.filter(item => item.name && item.value);
          state.allList.push({name:item,value: val})
        })
      } else {
        state.allList.push({name:'',value:val})
      }
    },
    delAll(state){
      state.checkColor = [];
      state.checkHead = [];
    }
  },
  actions: {
  },
  modules: {
  }
})
